var app = getApp()
Page({
  data:{
      error:false,
      status:true,  //data里面的属性可以传递到视图
      userInfo:'',
      title:'意见反馈',
      is_submit:false
  },
  onLoad: function(options) {
    var that = this;
    that.setData({ title:options.title });
  },
  bindHideKeyboard:function(e){
      var that = this;
      if(e.detail.value.length) that.setData({ is_submit:true });
      else that.setData({ is_submit:false });
  },
  formSubmit: function(e) {
    var content = e.detail.value;

    if( content.content.length ){        
        var that = this;
        var name = app.globalData.userInfo.nickName;
        wx.request({
            url: app.globalData.domain+'/wx/index.php',
            method:'POST',
            data: {'openid': '','name':name,'content':content.content,'position':that.data.title,'type': 'suggest' },
            header: {'Content-Type': 'application/x-www-form-urlencoded'},
            success: function(res) {
                if(!res.data.error){
                    that.setData({status:false});
                    setTimeout(function () {
                        that.setData({status:true});
                        wx.switchTab({
                            url: '../index/index'
                        })
                    }, 2000);
                }else{
                    that.setData({error:true});
                }
            }
        });
    }

  }
})